/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ylystudio.pms.ejb.entity;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author Kenny Lin
 */
@Entity
@Table(name = "insure_middle")
@NamedQueries({
    @NamedQuery(name = "InsureMiddle.findAll", query = "SELECT i FROM InsureMiddle i"),
    @NamedQuery(name = "InsureMiddle.findByInsureMoney", query = "SELECT i FROM InsureMiddle i WHERE i.insureMoney = :insureMoney"),
    @NamedQuery(name = "InsureMiddle.findByUserId", query = "SELECT i FROM InsureMiddle i WHERE i.insureMiddlePK.userId = :userId"),
    @NamedQuery(name = "InsureMiddle.findByInsureId", query = "SELECT i FROM InsureMiddle i WHERE i.insureMiddlePK.insureId = :insureId")})
public class InsureMiddle implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected InsureMiddlePK insureMiddlePK;
    @Basic(optional = false)
    @Column(name = "insure_money")
    private double insureMoney;
    @JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private User user;
    @JoinColumn(name = "insure_id", referencedColumnName = "insure_id", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Insure insure;

    public InsureMiddle() {
    }

    public InsureMiddle(InsureMiddlePK insureMiddlePK) {
        this.insureMiddlePK = insureMiddlePK;
    }

    public InsureMiddle(InsureMiddlePK insureMiddlePK, double insureMoney) {
        this.insureMiddlePK = insureMiddlePK;
        this.insureMoney = insureMoney;
    }

    public InsureMiddle(int userId, int insureId) {
        this.insureMiddlePK = new InsureMiddlePK(userId, insureId);
    }

    public InsureMiddlePK getInsureMiddlePK() {
        return insureMiddlePK;
    }

    public void setInsureMiddlePK(InsureMiddlePK insureMiddlePK) {
        this.insureMiddlePK = insureMiddlePK;
    }

    public double getInsureMoney() {
        return insureMoney;
    }

    public void setInsureMoney(double insureMoney) {
        this.insureMoney = insureMoney;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Insure getInsure() {
        return insure;
    }

    public void setInsure(Insure insure) {
        this.insure = insure;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (insureMiddlePK != null ? insureMiddlePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof InsureMiddle)) {
            return false;
        }
        InsureMiddle other = (InsureMiddle) object;
        if ((this.insureMiddlePK == null && other.insureMiddlePK != null) || (this.insureMiddlePK != null && !this.insureMiddlePK.equals(other.insureMiddlePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.ylystudio.pms.ejb.entity.InsureMiddle[insureMiddlePK=" + insureMiddlePK + "]";
    }

}
